package com.yzt.zhuju.widget;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.yzt.zhuju.R;

/**
 * author : bob
 * date   : 2022/12/1
 * desc   :
 */
public class GenderAgeView extends LinearLayout {

    private final Context mContext;

    private LinearLayout mItemLayout;

    private ImageView mGenderIv;

    private TextView mAgeTv;

    public GenderAgeView(Context context) {
        super(context);
        mContext = context;
        initView();
    }

    public GenderAgeView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        initView();
    }

    public GenderAgeView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        initView();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public GenderAgeView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mContext = context;
        initView();
    }

    private void initView() {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.view_layout_gender_age, this, true);
        mItemLayout = mView.findViewById(R.id.item_layout);
        mGenderIv = mView.findViewById(R.id.gender_iv);
        mAgeTv = mView.findViewById(R.id.age_tv);
    }

    public void setUserInfo(int gender, int age) {
        if (gender == 2) {
            mGenderIv.setImageResource(R.mipmap.icon_girl);
            mItemLayout.setBackgroundResource(R.drawable.round_gender_girl);
        } else {
            mGenderIv.setImageResource(R.mipmap.icon_boy);
            mItemLayout.setBackgroundResource(R.drawable.round_gender_boy);
        }
        mAgeTv.setText(String.valueOf(age));
    }
}

